import type { TreeKey, TreeNode, TreeNodeData } from 'element-plus/es/components/tree-v2/src/types';
import type { ComputedRef } from 'vue';
export interface TreeDataArr {
  id?: string;
  sn?: number;
  key: string;
  level?: number;
  parent?: TreeNode;
  children?: TreeDataArr[];
  data?: TreeNodeData;
  disabled?: boolean;
  label?: string;
  isLeaf?: boolean;
  type?: string;
  category?: number;
  ranks?: number;
  title?: string;
}

export interface SzTreePropsType {
  /**
   * 数据
   */
  treeData?: TreeDataArr[];
  /**
   *  二级状态 1 正常  2查询全部 3归档单位查询
   */
  letTopTwoState?: 1 | 2 | 3;
  /**
   * 展开keys
   */
  expandedKeys?: string[];
  /**
   * tree 高度
   */
  treeHegith?: number;
  //currentKey 选中key
  currentKey?: string | null;
  /**拖拽节点功能-哪些可以拖拽 */
  szDraggable?: 'all' | '';
  /**是否显示复选框 */
  showCheckbox?: boolean;
  /** 每个树节点用来作为唯一标识的属性，整棵树应该是唯一的*/
  nodeKey?: string;
  onCurrentChange?: (data: TreeDataArr) => void;
  onNodeClick?: (data: TreeDataArr) => void;
  onNodeExpand?: (data: TreeDataArr) => void;
  onNodeCollapse?: (data: TreeDataArr) => void;

  /**在显示复选框的情况下，是否严格的遵循父子不互相关联的做法，默认为 false */
  checkStrictly?: boolean;
  /**筛选字段 */
  filterText?: string;
  /**当某一节点被鼠标右键点击时会触发该事件 */
  onNodeContextmenu?: (event: any, data: any, node: any, components: any) => void;
  /** 默认勾选的节点的 key 的数组*/
  defaultCheckedKeys?: string[];
}

export interface UseSzTreeMethods {
  /**
   * 设置 tree 参数
   */
  setTreeProps: (props: Partial<SzTreePropsType>) => void;
  /**
   * 展开状态
   */
  expandStateComp: ComputedRef<number>;
  /**
   * 展开收起事件
   */
  expandTap: () => void;
  /**
   * 获取selectObj
   */
  getSelectObjComp: ComputedRef<TreeDataArr | undefined>;

  /**
   * 可移动状态
   * 1上移 2下移  3上下  4不可移动
   */
  getMoveComp: ComputedRef<number>;

  /**
   * 移动事件
   * up上移  down下移
   */
  moveTap: (type: 'up' | 'down', api: (p: any) => Promise<any>) => void;
  /**
   *设置 selectObj
   */
  setSelectObj: (select: TreeDataArr | undefined) => void;
  /**
   * tree 滚动到当前元素
   */
  treesCrollTo: () => void;
  /**设置加载状态 */
  setLoading: (bool: boolean) => void;
  /**获取加载状态 */
  getLoading: ComputedRef<boolean>;
  /**获取treeRef */
  getTreeRef: ComputedRef;
  /**通过 keys 设置目前勾选的节点 */
  setCheckedKeys: (keys: TreeKey[]) => void;
  /**若节点可被选择（即show-checkbox为 true），则返回目前被选中的节点所组成的数组 */
  getCheckedNodes: (bool?: boolean) => any;
}

export interface TreeMethods {
  setTreeProps: (props: SzTreePropsType) => void;
  treesCrollTo: () => void;
  setLoading: (bool: boolean) => void;
  getTreeRef: ComputedRef;
  setCheckedKeys: (keys: TreeKey[]) => void;
  getCheckedNodes: (bool: boolean) => any;
}
